% Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite

{\ttfamily \raggedright {
\noindent
\mbox{}\textbf{\textcolor{RoyalBlue}{\#include}}\ \texttt{\textcolor{Red}{$<$iostream$>$}} \\
\mbox{}\textbf{\textcolor{RoyalBlue}{\#include}}\ \texttt{\textcolor{Red}{$<$algorithm$>$}} \\
\mbox{}\textbf{\textcolor{RoyalBlue}{\#include}}\ \texttt{\textcolor{Red}{$<$queue$>$}} \\
\mbox{} \\
\mbox{}\textbf{\textcolor{Blue}{using}}\ \textbf{\textcolor{Blue}{namespace}}\ std\textcolor{BrickRed}{;} \\
\mbox{} \\
\mbox{}\textbf{\textcolor{Blue}{struct}}\ edge\textcolor{Red}{\{} \\
\mbox{}\ \ \textcolor{ForestGreen}{int}\ to\textcolor{BrickRed}{,}\ weight\textcolor{BrickRed}{;} \\
\mbox{}\ \ \textbf{\textcolor{Black}{edge}}\textcolor{BrickRed}{()}\ \textcolor{Red}{\{\}} \\
\mbox{}\ \ \textbf{\textcolor{Black}{edge}}\textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ t\textcolor{BrickRed}{,}\ \textcolor{ForestGreen}{int}\ w\textcolor{BrickRed}{)}\ \textcolor{BrickRed}{:}\ \textbf{\textcolor{Black}{to}}\textcolor{BrickRed}{(}t\textcolor{BrickRed}{),}\ \textbf{\textcolor{Black}{weight}}\textcolor{BrickRed}{(}w\textcolor{BrickRed}{)}\ \textcolor{Red}{\{\}} \\
\mbox{}\ \ \textcolor{ForestGreen}{bool}\ \textbf{\textcolor{Blue}{operator}}\ \textcolor{BrickRed}{$<$}\ \textcolor{BrickRed}{(}\textbf{\textcolor{Blue}{const}}\ edge\ \textcolor{BrickRed}{\&}that\textcolor{BrickRed}{)}\ \textbf{\textcolor{Blue}{const}}\ \textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{return}}\ weight\ \textcolor{BrickRed}{$>$}\ that\textcolor{BrickRed}{.}weight\textcolor{BrickRed}{;} \\
\mbox{}\ \ \textcolor{Red}{\}} \\
\mbox{}\textcolor{Red}{\}}\textcolor{BrickRed}{;} \\
\mbox{} \\
\mbox{}\textcolor{ForestGreen}{int}\ \textbf{\textcolor{Black}{main}}\textcolor{BrickRed}{()}\textcolor{Red}{\{} \\
\mbox{}\ \ \textcolor{ForestGreen}{int}\ N\textcolor{BrickRed}{,}\ C\textcolor{BrickRed}{=}\textcolor{Purple}{0}\textcolor{BrickRed}{;} \\
\mbox{}\ \ \textbf{\textcolor{Black}{scanf}}\textcolor{BrickRed}{(}\texttt{\textcolor{Red}{"{}\%d"{}}}\textcolor{BrickRed}{,}\ \textcolor{BrickRed}{\&}N\textcolor{BrickRed}{);} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{while}}\ \textcolor{BrickRed}{(}N\textcolor{BrickRed}{-\/-}\ \textcolor{BrickRed}{\&\&}\ \textcolor{BrickRed}{++}C\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \textcolor{ForestGreen}{int}\ n\textcolor{BrickRed}{,}\ m\textcolor{BrickRed}{,}\ s\textcolor{BrickRed}{,}\ t\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Black}{scanf}}\textcolor{BrickRed}{(}\texttt{\textcolor{Red}{"{}\%d\ \%d\ \%d\ \%d"{}}}\textcolor{BrickRed}{,}\ \textcolor{BrickRed}{\&}n\textcolor{BrickRed}{,}\ \textcolor{BrickRed}{\&}m\textcolor{BrickRed}{,}\ \textcolor{BrickRed}{\&}s\textcolor{BrickRed}{,}\ \textcolor{BrickRed}{\&}t\textcolor{BrickRed}{);} \\
\mbox{}\ \ \ \ vector\textcolor{BrickRed}{$<$}edge\textcolor{BrickRed}{$>$}\ g\textcolor{BrickRed}{[}n\textcolor{BrickRed}{];} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{while}}\ \textcolor{BrickRed}{(}m\textcolor{BrickRed}{-\/-)}\textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \ \ \textcolor{ForestGreen}{int}\ u\textcolor{BrickRed}{,}\ v\textcolor{BrickRed}{,}\ w\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \ \ \textbf{\textcolor{Black}{scanf}}\textcolor{BrickRed}{(}\texttt{\textcolor{Red}{"{}\%d\ \%d\ \%d"{}}}\textcolor{BrickRed}{,}\ \textcolor{BrickRed}{\&}u\textcolor{BrickRed}{,}\ \textcolor{BrickRed}{\&}v\textcolor{BrickRed}{,}\ \textcolor{BrickRed}{\&}w\textcolor{BrickRed}{);} \\
\mbox{}\ \ \ \ \ \ g\textcolor{BrickRed}{[}u\textcolor{BrickRed}{].}\textbf{\textcolor{Black}{push$\_$back}}\textcolor{BrickRed}{(}\textbf{\textcolor{Black}{edge}}\textcolor{BrickRed}{(}v\textcolor{BrickRed}{,}\ w\textcolor{BrickRed}{));} \\
\mbox{}\ \ \ \ \ \ g\textcolor{BrickRed}{[}v\textcolor{BrickRed}{].}\textbf{\textcolor{Black}{push$\_$back}}\textcolor{BrickRed}{(}\textbf{\textcolor{Black}{edge}}\textcolor{BrickRed}{(}u\textcolor{BrickRed}{,}\ w\textcolor{BrickRed}{));} \\
\mbox{}\ \ \ \ \textcolor{Red}{\}} \\
\mbox{} \\
\mbox{}\ \ \ \ \textcolor{ForestGreen}{int}\ d\textcolor{BrickRed}{[}n\textcolor{BrickRed}{];} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ i\textcolor{BrickRed}{=}\textcolor{Purple}{0}\textcolor{BrickRed}{;}\ i\textcolor{BrickRed}{$<$}n\textcolor{BrickRed}{;}\ \textcolor{BrickRed}{++}i\textcolor{BrickRed}{)}\ d\textcolor{BrickRed}{[}i\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ INT$\_$MAX\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ d\textcolor{BrickRed}{[}s\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ \textcolor{Purple}{0}\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ priority$\_$queue\textcolor{BrickRed}{$<$}edge\textcolor{BrickRed}{$>$}\ q\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ q\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{push}}\textcolor{BrickRed}{(}\textbf{\textcolor{Black}{edge}}\textcolor{BrickRed}{(}s\textcolor{BrickRed}{,}\ \textcolor{Purple}{0}\textcolor{BrickRed}{));} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{while}}\ \textcolor{BrickRed}{(}q\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{empty}}\textcolor{BrickRed}{()}\ \textcolor{BrickRed}{==}\ \textbf{\textcolor{Blue}{false}}\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \ \ \textcolor{ForestGreen}{int}\ node\ \textcolor{BrickRed}{=}\ q\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{top}}\textcolor{BrickRed}{().}to\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \ \ \textcolor{ForestGreen}{int}\ dist\ \textcolor{BrickRed}{=}\ q\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{top}}\textcolor{BrickRed}{().}weight\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \ \ q\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{pop}}\textcolor{BrickRed}{();} \\
\mbox{} \\
\mbox{}\ \ \ \ \ \ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(}dist\ \textcolor{BrickRed}{$>$}\ d\textcolor{BrickRed}{[}node\textcolor{BrickRed}{])}\ \textbf{\textcolor{Blue}{continue}}\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \ \ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(}node\ \textcolor{BrickRed}{==}\ t\textcolor{BrickRed}{)}\ \textbf{\textcolor{Blue}{break}}\textcolor{BrickRed}{;} \\
\mbox{} \\
\mbox{}\ \ \ \ \ \ \textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ i\textcolor{BrickRed}{=}\textcolor{Purple}{0}\textcolor{BrickRed}{;}\ i\textcolor{BrickRed}{$<$}g\textcolor{BrickRed}{[}node\textcolor{BrickRed}{].}\textbf{\textcolor{Black}{size}}\textcolor{BrickRed}{();}\ \textcolor{BrickRed}{++}i\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \ \ \ \ \textcolor{ForestGreen}{int}\ to\ \textcolor{BrickRed}{=}\ g\textcolor{BrickRed}{[}node\textcolor{BrickRed}{][}i\textcolor{BrickRed}{].}to\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \ \ \ \ \textcolor{ForestGreen}{int}\ w$\_$extra\ \textcolor{BrickRed}{=}\ g\textcolor{BrickRed}{[}node\textcolor{BrickRed}{][}i\textcolor{BrickRed}{].}weight\textcolor{BrickRed}{;} \\
\mbox{} \\
\mbox{}\ \ \ \ \ \ \ \ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(}dist\ \textcolor{BrickRed}{+}\ w$\_$extra\ \textcolor{BrickRed}{$<$}\ d\textcolor{BrickRed}{[}to\textcolor{BrickRed}{])}\textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \ \ \ \ \ \ d\textcolor{BrickRed}{[}to\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ dist\ \textcolor{BrickRed}{+}\ w$\_$extra\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \ \ \ \ \ \ q\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{push}}\textcolor{BrickRed}{(}\textbf{\textcolor{Black}{edge}}\textcolor{BrickRed}{(}to\textcolor{BrickRed}{,}\ d\textcolor{BrickRed}{[}to\textcolor{BrickRed}{]));} \\
\mbox{}\ \ \ \ \ \ \ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \ \ \ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Black}{printf}}\textcolor{BrickRed}{(}\texttt{\textcolor{Red}{"{}Case\ \#\%d:\ "{}}}\textcolor{BrickRed}{,}\ C\textcolor{BrickRed}{);} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(}d\textcolor{BrickRed}{[}t\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{$<$}\ INT$\_$MAX\textcolor{BrickRed}{)}\ \textbf{\textcolor{Black}{printf}}\textcolor{BrickRed}{(}\texttt{\textcolor{Red}{"{}\%d}}\texttt{\textcolor{CarnationPink}{\textbackslash{}n}}\texttt{\textcolor{Red}{"{}}}\textcolor{BrickRed}{,}\ d\textcolor{BrickRed}{[}t\textcolor{BrickRed}{]);} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{else}}\ \textbf{\textcolor{Black}{printf}}\textcolor{BrickRed}{(}\texttt{\textcolor{Red}{"{}unreachable}}\texttt{\textcolor{CarnationPink}{\textbackslash{}n}}\texttt{\textcolor{Red}{"{}}}\textcolor{BrickRed}{);} \\
\mbox{}\ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{return}}\ \textcolor{Purple}{0}\textcolor{BrickRed}{;} \\
\mbox{}\textcolor{Red}{\}} \\

} \normalfont\normalsize
